package com.github.bridge.client.esign;

import com.dtflys.forest.annotation.*;
import com.dtflys.forest.callback.OnProgress;
import com.dtflys.forest.extensions.DownloadFile;
import com.github.bridge.client.esign.request.*;
import com.github.bridge.client.esign.response.*;

import java.io.File;
import java.io.InputStream;
import java.util.Map;

@Address(source = ESignAddress.class)
//@Success(condition = ESignSuccessCondition.class)
//@Retry(maxRetryCount = "1", maxRetryInterval = "15")
public interface ESignClient {

    @Post("/esign-signs/v1/signFlow/createAndStart")
    ESignResult<CreateAndStartResponse> createAndStart(@Header CommonHerder herder, @JSONBody CreateAndStartRequest request);


    @Post("/esign-docs/v1/documents/template/generatePdfFile")
    ESignResult<GeneratePdfFileResponse> generatePdfFile(@Header CommonHerder herder, @JSONBody GeneratePdfFileRequest request);

    /**
     * 文件直传
     * @param file
     * @return
     */
    @Post("/file/v1/uploadWithAuth")
    ESignResult<FileUploadResponse> uploadWithAuth(@Header CommonHerder herder, @DataFile("file") File file, @FormBody UploadWithAuthRequest request);


    @Get("/file/v1/getFileStream")
    InputStream getFileStream(@Header CommonHerder herder, @Query("fileKey") String fileKey);

    @Get("/file/v1/getFileStream")
    @DownloadFile(dir = "${dir}", filename = "${filename}")
    File downloadFile(@Header CommonHerder herder, @Query("fileKey") String fileKey,
                      @Var("dir") String dir, @Var("filename") String filename, OnProgress onProgress);

    @Get("/file/v1/getDownloadUrl")
    ESignResult<GetDownloadUrlResponse> getDownloadUrl(@Header CommonHerder herder, @Query("fileKey") String fileKey);

    @Post("/esign-docs/v1/documents/template/contents")
    ESignResult<TemplateContentResponse> templateContent(@Header CommonHerder herder, @JSONBody TemplateContentRequest request);

    @Post("/esign-docs/v1/documents/template/pdfPreviewUrl")
    ESignResult<PdfPreviewUrlResponse> pdfPreviewUrl(@Header CommonHerder herder, @JSONBody PdfPreviewUrlRequest request);

    @Get("/esign-signs/v1/signFlow/signDetail")
    ESignResult<SignDetailResponse> signDetail(@Header CommonHerder herder, @Query SignDetailRequest request);

    @Post("/etl-integrate/v1/client/getAccessToken")
    ESignResult<Map<String, String>> getAccessToken(@JSONBody Map<String, Object> map);
    @Post("/etl-integrate/v1/client/getSsoToken")
    ESignResult<Map<String, String>> getSsoToken(@JSONBody Map<String, Object> map);

}
